package 原型模式.深拷贝.再次clone方式;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Sheep implements Cloneable {
    String name;
    Sheep friends;  // 深拷贝：也为引用类型分配存储空间

    public Sheep(String name) {
        this.name = name;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Sheep sheep =(Sheep) super.clone();
        Sheep deep =(Sheep) friends.clone();
        sheep.friends = deep;
        return sheep;

    }

    public static void main(String[] args) {
        Sheep sheep1 = new Sheep("第一只羊");
        Sheep sheep2 = new Sheep("第二只羊");
        sheep1.friends = sheep2;

        System.out.println(sheep1.friends == sheep2);// true

    }


}
